package com.soft.mybatis.mapper;

import com.soft.mybatis.entity.Orders;
import com.soft.mybatis.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrdersMapper {
   Orders getOrderByNumber(String number);

   Orders getOrderOrderDetailUserById(Integer id);

   //注解方式作业1：查询订单信息及其下单者信息 OO
   @Select("select * from orders where id = #{oid}")
   @Results({
           @Result(id = true,property = "id",column = "id"),
           @Result(property = "userId",column = "user_id"),
           @Result(property = "user",column = "user_id",javaType = User.class,
                   one = @One(select = "com.soft.mybatis.mapper.UserMapper.selectUser"))
   })
   Orders selectOrderAndUserById(Integer oid);

   //注解方式作业2：每个订单中包含的商品信息 OM
   @Select("select * from orders where id = #{id}")
   @Results({
           @Result(id = true,property = "id",column = "id"),
           @Result(property = "userId",column = "user_id"),
           @Result(property = "orderDetailsList",column = "id",javaType = List.class,
                   many = @Many(select = "com.soft.mybatis.mapper.OrderDetailMapper.selectOrderDetailAndItemById"))
   })
   Orders selectOrderAndItemById(Integer id);
}
